"use server";

import { prisma } from "@/utils/db";
import { FieldType } from "./listDeal";

export const heatList = async (start: string, end: string) => {
  const result = await prisma.heat.findMany({
    orderBy: {
      time: "asc",
    },
    where: {
      time: {
        gte: start,
        lte: end,
      },
    },
  });
  return result;
};
export const heatAdd = async (data: FieldType) => {
  try {
    const isExit = await prisma.heat.findFirst({
      where: {
        time: data.time,
      },
    });
    if (isExit) {
      return "该日期已经存在";
    }
    const result = await prisma.heat.create({
      data,
    });
    return true;
  } catch (err) {
    console.log(err);
    return "添加失败";
  }
};
export const heatUpdate = async (id: number, data: FieldType) => {
  try {
    const result = await prisma.heat.update({
      where: {
        id: id,
      },
      data: data,
    });
    return true;
  } catch (err: any) {
    return err.message.toString();
  }
};
